import { createApp } from 'vue'
import ElementPlus, { ElMessage } from 'element-plus'
import 'element-plus/dist/index.css'
/*import "echarts";
import ECharts from 'vue-echarts'*/
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import App from './App.vue'
import axios from 'axios'
import router from './router/index'
import { store } from './store'
import * as ElIcons from '@element-plus/icons-vue'

axios.defaults.baseURL = "https://nacos.inquark.com:66/api";
// axios.defaults.baseURL = "http://localhost:8084";
const app = createApp(App);
app.config.globalProperties.$http = axios;
app.config.globalProperties.$http.interceptors.request.use(
    (re) => {
        if (localStorage.token) {
            re.headers.Authorization = localStorage.token;
        }
        return re;
    }, error => {
        return Promise.reject(error);
    })
app.config.globalProperties.$http.interceptors.response.use(re => {
    if (re.status === 401) {
        localStorage.removeItem("token");
        router.push("/");
        ElMessage.error("请进行登录");
    }
    return re;
}, error => {
    return Promise.reject(error);
})

for (const name in ElIcons) {
    app.component(name, ElIcons[name])
}
//app.component('v-chart', ECharts)
app.use(router)
app.use(ElementPlus, { locale: zhCn })
app.use(store)
app.mount('#app')